package 剑指offerII;

import java.util.HashSet;
import java.util.Set;

public class _93最长斐波那契数列 {
    public int lenLongestFibSubseq(int[] arr) {
        int res = 0;
        Set<Integer> set = new HashSet<>();
        for(int num : arr){
            set.add(num);
        }
        for(int i = 0; i < arr.length; i++){
            for(int j = i + 1; j < arr.length; j++){
                int a = arr[j];
                int b = arr[i] + arr[j];
                int len = 2;
                while (set.contains(b)){
                    len++;
                    int tem = b;
                    b = a + b;
                    a = tem;
                    res = res > len ? res : len;
                }
            }
        }
        return res;
    }
}
